'''
Created on 09/12/2009

@author: eh01
'''
from subprocess import CalledProcessError
import subprocess
import logging
import os
import sys

if __name__ == '__main__':
    # location of script
    script_loc = os.path.dirname(__file__) + '/boot.py'
    # command to run the script
    cmnd = """python "%s" %s""" % (script_loc, ' '.join(sys.argv[1:]))

    while True:
        try:
            # run the command and wait for it to complete. If the exit code is zero it will return, otherwise it will
            # raise a CalledProcessError
            subprocess.check_call(cmnd)
            # if we reach here, that means the process existed with a zero code, hence we will break the loop and
            # hence perform a "quit"
            break;
        except CalledProcessError:
            # when the process exits with anything other than a zero, we will do a restart by going through the loop again.
            pass
        